package com.yxd.demo.util;

import cn.hutool.json.JSONUtil;
import com.yxd.demo.domain.Rule;
import com.yxd.demo.domain.Store;
import lombok.extern.slf4j.Slf4j;
import org.jeasy.rules.api.Facts;
import org.jeasy.rules.api.Rules;
import org.jeasy.rules.api.RulesEngineListener;
import org.springframework.stereotype.Component;

/**
 * @author: yxd
 * @date: 2022/8/1 17:04
 */
@Component
@Slf4j
public class MyRulesEngineListener implements RulesEngineListener {
    @Override
    public void beforeEvaluate(Rules rules, Facts facts) {
        log.info("[before]规则名称：{}, 事实对象：{}", JSONUtil.toJsonStr(rules), JSONUtil.toJsonStr(facts));
    }

    @Override
    public void afterExecute(Rules rules, Facts facts) {
        /*Store store = (Store)facts.get("store");
        log.info("获取到购买的商家商品:{}", JSONUtil.toJsonStr(store));*/
        log.info("------执行其他逻辑------");
    }
}
